package gamehistory.challenge;

import gamehistory.utils.xml.XMLModel;

import java.util.ArrayList;

import scg.gen.OfferTrans;
import scg.gen.ReofferTrans;

/**
 * 
 * @author Brent Kersanske
 *
 */
public class OfferHistoryModel extends XMLModel {
	
	private static final String OFFER_HISTORY = "offerHistory";

	private ArrayList<OfferModel> offers;
	
	/**
	 * Constructor.
	 * @param creator
	 * @param initialOffer
	 */
	public OfferHistoryModel(String creator, OfferTrans initialOffer) {
		super(OFFER_HISTORY);
		OfferModel startingEntry = new OfferModel(creator, initialOffer);
		this.offers 			 = new ArrayList<OfferModel> ();
		this.offers.add(startingEntry);
	}
	
	/**
	 * 
	 * @param player
	 * @param newOffer
	 */
	public void assimilateReoffer(String player, ReofferTrans newOffer) {
		double previousPrice = this.offers.get(this.offers.size() - 1).getPrice();
		OfferModel newEntry  = new OfferModel(player, newOffer, previousPrice);		
		this.offers.add(newEntry);
	}
	
	/**
	 * 
	 * @return
	 */
	public ArrayList<OfferModel> getOffers() {
		return this.offers;
	}
	
	/**
	 * 
	 * @return
	 */
	public Double getFinalPrice() {
		return offers.get(offers.size() - 1).getPrice();
	}
	
	/**
	 * 
	 * @return
	 */
	public Double getOriginalPrice() {
		return offers.get(0).getPrice();
	}

	/**
	 * @{inheritDoc}
	 */
	public void buildModel() {
		for(OfferModel offerModel : this.offers) {
			offerModel.buildModel();
			addChildModel(offerModel);
		}
	}
}
